supernovaffxifandomcom-20200216-history
Rotha's GearSwap Lessons
Intro This guide is designed to help you create GearSwap files in a step-by-step manner. It'll start with the very basic, and will progress to more advanced techniques as this page gets updated. Although the example codes are designed for Black Mages, the techniques involved will work for all jobs. This page is currently a work in progress. Before you begin Make sure you have Notepad++ installed on your PC. It makes reading and writing code so much easier than normal notepad. Also, turn on the GearSwap addon in Windower if you have not already. The Basics Now for the fun part. Here we are going to learn how layout the script, set equipment, and create basic conditions on when to activate the different functions of the script. The tutorial below will use, as an example, a Black Mage casting the spell "Flare". Layout All GearSwap users files should be stored in C:\Program Files (x86)\Windower4\addons\GearSwap\data\ Any time you log in, or change jobs, GearSwap will look there for file that correspond to your current job. For example, if you change job to Black Mage, it will look for a blm.lua file and automatically load it if one exist. In Notepad++, create a new file, choose a job to name it, and save it as a Lua Source Type. This will make it so the file extension is .lua. For this tutorial, we'll be using Black Mage as our example. So, we'll go ahead and create a blm.lua file and save it in the data folder. Now that we have blm.lua created, open it and enter the following lines: function get_sets() --This function prepares your equipment sets. end ---------------------------------------------------------------------- function precast(spell) --This function performs right before the action is sent to the server. end ---------------------------------------------------------------------- function midcast(spell) --This function performs after precast but before the action is sent to the server. end ---------------------------------------------------------------------- function aftercast(spell) --This function performs after the action has taken place end ---------------------------------------------------------------------- Equipment Sets Now lets look at function get_sets(). Below it, you'll write out all of the possible equipment sets you'll be swapping. But for now, let's just work with a couple of equipment pieces. In the function, edit it so that it looks like: function get_sets() sets.precast = {} sets.midcast = {} sets.aftercast = {} end Now lets start filling in equipment. For our example, we'll equip gear as if we're about to cast the spell "Flare" function get_sets() sets.precast = {sub="Vivid Strap +1",feet="Rostrum Pumps"} sets.midcast = {main="Vulcan's Staff",sub="Fire Grip"} sets.aftercast = {main="Terra's Staff",feet="Herald's Gaiters"} end Based on our equipment, right before the we cast "Flare", precast will equip "Vivid Strap +1" and "Rostrum pumps" for their "Fast Cast" traits. For a mage, precast is mainly used in trying to activate "Fast Cast". For melee, precast is used for preparing beneficial traits for weaponskills. Right before "Flare" activates, midcast then equip gear that will benefit its fire element After Flare is casted, aftercast will equip "Terra's Staff" and "Herald's Gaiters" for their defensive traits. Remember, we've so far only made our equipment sets. The codes so far won't work until we fill in the rest of the functions. Precast Let's look at function precast(spell). '''This function is called right before your spell/ability/weaponskill is activated. function precast(spell) equip(sets.precast) end By putting in '''equip(sets.precast), '''any time you're about to perform '''any spell/ability/weaponskill, your equipment will be changed based on the sets.precast = {} '''table. If you want to specify conditions on when it should activate, you'll have to use '''if '''statements. We'll go ahead and use them for the next function. ''Midcast & Conditional Statements'' Now it's time for '''function midcast(spell). '''This function comes after precast but before the spell/ability/weaponskill takes place. Since our example is what to equip when casting "Flare", we'll have to make a conditional statement so that it will only activate when "Flare" is casted. function midcast(spell) if spell.english "Flare" then equip(sets.midcast) end end This above example will look at the action you took, and check its English name. It will compare it to the term "Flare". If they match, then it will equip gear based on '''sets.midcast = {}. '''If it does not match, then it will ignore, and not do anything else in the function. ''Aftercast'' And finally, we have '''function aftercast(spell). '''This function is called after performing your spell/ability/weaponskill. You'll want to use this function to go back to your default gear. function aftercast(spell) equip(sets.aftercast) end This will equip your gear based on '''sets.aftercast = {} '''after your actions has taken place. ''Putting it together'' Now that we have a complete set, let's have a look at it as a whole. function get_sets() sets.precast = {sub="Vivid Strap +1",feet="Rostrum Pumps"} sets.midcast = {main="Vulcan's Staff",sub="Fire Grip"} sets.aftercast = {main="Terra's Staff",feet="Herald's Gaiters"} end ---------------------------------------------------------------------- function precast(spell) equip(sets.precast) end ---------------------------------------------------------------------- function midcast(spell) if spell.english "Flare" then equip(sets.midcast) end end ---------------------------------------------------------------------- function aftercast(spell) equip(sets.aftercast) end ---------------------------------------------------------------------- Go ahead and try it! You'll see that it work. However, there's one small problem. You'll definitely want to more than "Flare" to just change equipment. You have hundreds of other spells and abilities! So, instead of occupying the main tables (sets.precast, sets.midcast, sets.aftercast), you'll want to make your own. We call these '''sub-tables. The Basics: Sub-tables function get_sets() sets.precast = {} sets.precast.fc = {sub="Vivid Strap +1",feet="Rostrum Pumps"} sets.midcast = {} sets.midcast.flare = {main="Vulcan's Staff",sub="Fire Grip"} sets.midcast.quake = {main="Terra's Staff",sub="Earth Grip"} sets.aftercast = {main="Terra's Staff",feet="Herald's Gaiters"} end ---------------------------------------------------------------------- function precast(spell) if spell.type:contains('Magic') then equip(sets.precast.fc) end end ---------------------------------------------------------------------- function midcast(spell) if spell.english "Flare" then equip(sets.midcast.flare) end if spell.english "Quake" then equip(sets.midcast.quake) end end ---------------------------------------------------------------------- function aftercast(spell) equip(sets.aftercast) end ---------------------------------------------------------------------- Above in bold are the changes made to accommodate future actions and equipment swaps. sets.precast = {} 'and '''sets.midcast = {} '''were left blank so that those main tables exist. Without them, their sub-tables will not work at all. '''sets.precast.fc '''is a sub-table that was made for "Fast Cast". You could've named it sets.precast.'anything. '''fc was easy enough to remember for "Fast Cast". If you decide to name it something else, just remember to call it correctly in your precast function. '''sets.midcast.flare was created specifically for the spell "Flare". You can add more spells by creating more subtables with unique names below it and creating their respective equipment sets. (example sets.midcast.quake) In function precast(spell), 'you'll notice a new condition. What is happening here is the function is looking at your action, and checking its type. It'll find either '''JobAbility, Weaponskill, WhiteMagic, BlackMagic, BardSong, '''or something else. It will compare what it finds with the term "'Magic". If the type it finds contains '''"Magic" whether its BlackMagic or WhiteMagic, it will return as true and work the rest of the command '''equip(sets.precast.fc). '''If the type it finds does not contain the term "Magic", then it will ignore and no action will take place in this function. In '''function midcast(spell), '''when conditions are met, it will now call upon either '''sets.midcast.flare or sets.midcast.quake and equip the appropriate gear. Conclusion So far, we've learned how to create the basic layout of a GearSwap file, make equipment sets, and formulate conditions on when gear swapping should take place. With this basic understand, you can create rudimentary gearswap files for any spell, or ability.